<template>
    <div class="userSignUp-container">
        <div class="userSignUp-title">设置密码</div>
        <ul class="form-cont">
            <li class="form-num">
                <input type="password" class="pass-ipt" placeholder="设置登录密码" v-model="passNum">
            </li>
            <li class="form-confirm">
                <input type="password" class="confirm-ipt" placeholder="请确认密码" v-model="confirmNum">
            </li>
        </ul>
        <div class="pass-tip">密码由6-16位数字或字母组成</div>
        <div class="btn" @click="submitForm">
            确认
        </div>
    </div>
</template>
<script>
    import loginApi from '../../api/login.js';
    import { Toast } from 'mint-ui';
    export default {
        data () {
            return {
                passNum: '',
                confirmNum: '',
                phoneNum:'',
                verifyNum:'',
                arr: ['circlesure', 'listensure', 'microsure'],
                type:'',
                id: '',
                status: '',
                pid: ''
            }
        },
        created() {
            this.phoneNum = this.$route.query.tel;
            this.verifyNum = this.$route.query.conf;
            this.type = this.$route.query.type;
            this.id = this.$route.query.id;
            this.status = this.$route.query.status;
            this.pid = this.$route.query.pid;
        },
        methods: {
            submitForm () {
                if (!this.passNum || !this.confirmNum) {
                    Toast({
                        message: '密码不能为空',
                        duration: 2000
                    });
                } else if (this.passNum != this.confirmNum) {
                    Toast({
                        message: '密码不一致',
                        duration: 2000
                    });
                }
                else {
                    loginApi.signUp(this.phoneNum, this.verifyNum, this.passNum).then(res => {
                        if (res.code == 0) {
                            let obj = {};
                            obj.uid = res.result.id;
                            let str = JSON.stringify(obj)
                            localStorage.setItem('dongHang_common_user', str);
                            this.$router.push({path: `/${this.arr[this.type]}`, query:{
                                agentId: this.id,
                                status: this.status,
                                pid: this.pid
                            }})
                        } else {
                            Toast({
                                message: res.message,
                                duration: 2000
                            });
                        }
                    })
                }
            }
        }
    }
</script>
<style lang="less" scoped>
    .userSignUp-container {
        .userSignUp-title {
            font-size: .4rem;
            text-indent: .3rem;
            padding-top: .5rem;
            margin-bottom: .2rem;
        }
        .form-cont {
            li {
                padding: 0 0.3rem;
                height: 1rem;
                border-bottom: 1px solid #cccccc;
            }
            input {
                height: 1rem;
                float: left;
                border: 0;
                outline: none;
                font-size: 0.3rem;
                color: #282828;
                &::placeholder {
                    color: #707070;
                }
            }
            .pass-ipt {
                width: 3.5rem;
            }
            .confirm-ipt {
                width: 3.5rem;
            }
        }
        .pass-tip {
            font-size: .3rem;
            margin-left: .3rem;
            margin-top: .25rem;
            color: #707070;
        }
    }
    
    .btn {
        margin: 1rem auto 0;
        width: 6.9rem;
        height: 0.8rem;
        font-size: 0.32rem;
        text-align: center;
        line-height: 0.80rem;
        color: #fff;
        background-color: #29abae;
        border-radius: 5px;
    }
</style>